﻿using DevExpress.XtraEditors;
using DevExpress.XtraGrid;
using DevExpress.XtraGrid.Views.BandedGrid;
using DevExpress.XtraGrid.Views.Base;
using DevExpress.XtraTreeList;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace HRM.DICTIONARY.DAL
{
    public interface ICommon<T> where T :class
    {
        //Constant call for each t entity
        BaseView BV { get; set; }
        string ErrMsg { get; set; }
        GridControl GC { get; set; }
        AdvBandedGridView GV { get; set; }
        T currEntity { get; set; }
        List<String> ValueOfGridViewRow { get; set; }
        Actions myAction { get; set; }
        String ColIDName { get; set; }
        String[] ColIDsName { get; set; }
        DbSet<T> DbSet { get; set; }
        DbContext dbEntities { get; set; }

        //Function for UI
        List<T> GetList();
        DataTable GetTable();
        bool AddCombo(System.Windows.Forms.ComboBox comBo, string displayMember, string valueMember, bool isHasAll);
        bool AddComboBoxEdit(DevExpress.XtraEditors.ComboBoxEdit comBo, string valueMember);
        bool AddCheckComboEdit(DevExpress.XtraEditors.CheckedComboBoxEdit checkedCombo, string displayMember, string valueMember);
        bool AddGridLookupEdit(DevExpress.XtraEditors.GridLookUpEdit gridLookup, string displayMember, string valueMember);
        bool AddGridLookupEdit(GridLookUpEdit gridlookup, string displayMember, string valueMember, DataTable dt);
        bool AddRepositoryGridLookupEdit(DevExpress.XtraEditors.Repository.RepositoryItemGridLookUpEdit repositoryItemGridLookUpEdit, string displayMember, string valueMember);
        bool AddRepositoryGridLookupEdit(DevExpress.XtraEditors.Repository.RepositoryItemGridLookUpEdit repositoryItemGridLookUpEdit, string displayMember, string valueMember, DataTable dt);
        bool AddGridControlFromTable();
        bool AddGridControlFromList();
        bool AddGridControlFromList(List<T> listSearch);
        bool AddTreeListControlFromTable(TreeList tl);
        void AddGridExport(DevExpress.XtraEditors.XtraUserControl parentForm);
        void AddGridExport(DevExpress.XtraEditors.XtraForm parentForm);

        //Function for Database
        T GetById(Object Id);
        long CountAll();
        bool Insert(T entity);
        bool Update(T entity);
        bool Delete(T entity);
        bool Delete(Object Id);
        List<T> Where(System.Linq.Expressions.Expression<Func<T, bool>> predicate);
        List<T> OrderBy(System.Linq.Expressions.Expression<Func<T, bool>> predicate);
        List<T> Distinct();
        T FirstElement();
        T LastElement();
        List<T> Include(string[] collections);

        //Function for Choose On Data GridView and Action After...
        T gbList_Click(object sender, EventArgs e);
        T gbList1_Click(object sender, EventArgs e);
        T gbListMultipleKey_Click(object sender, EventArgs e);
        T gbList_DoubleClick(object sender, EventArgs e);
        T gbList1_DoubleClick(object sender, EventArgs e);
        T gbList_MouseDown(object sender, MouseEventArgs e);
        T gbList1_MouseDown(object sender, MouseEventArgs e);
        T gbList_RowCellClick(object sender, DevExpress.XtraGrid.Views.Grid.RowCellClickEventArgs e);
        T gbList1_RowCellClick(object sender, DevExpress.XtraGrid.Views.Grid.RowCellClickEventArgs e);

        //Function for Interact with Data and not Reload Data
        bool DeleteOnGridView(T entity);
        bool InsertOnGridView(T entity);
        bool UpdateOnGridView(T entity);

        /// <summary>
        /// Generate the new ID for primary key in entity
        /// </summary>
        /// <param name="YourSign"></param>
        /// <returns></returns>
        string NewID(string YourSign);

        DataTable ConvertListToDataTable<T>(List<T> l_oItems);
    }

    public enum Actions
    {
        Insert,
        InsertMultiple,
        Update,
        Delete,
        View,
        Print
    }

    public enum CloseOrNew
    {
        Close, 
        New
    }
}
